package com.sahadev.mvp.model;

/**
 * Created by Sahadev on 2015/11/12.
 */

import android.os.Handler;
import android.os.Message;

import com.sahadev.mvp.other.IConnect;
import com.sahadev.mvp.other.IRequestData;

/**
 * 数据总接口
 */
public abstract class AbstIData implements IConnect ,IRequestData {
    //数据获取之后的回调接口
    protected Handler.Callback callback;

    public AbstIData(Handler.Callback callback) {
        this.callback = callback;
    }

    /**
     * 当成功之后会向callback发送Message.what=0的消息
     *
     * @param obj
     */
    public void onSuccess(Object obj) {
        Message msg = new Message();
        msg.what = 0;
        msg.obj = obj;
        callback.handleMessage(msg);
    }

    /**
     * 当失败之后会向callback发送Message.what=1的消息
     *
     * @param obj
     */
    public void onFailed(Object obj) {
        Message msg = new Message();
        msg.what = 1;
        msg.obj = obj;
        callback.handleMessage(msg);
    }

}